//
//  NavigationController.swift
//  Test
//
//  Created by ZWJY on 2021/9/18.
//

import UIKit

///自定义导航条
class NavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //隐藏系统导航条
        navigationBar.isHidden = true
        // 取消模糊
        navigationBar.isTranslucent = false
    }

    /// 设置默认颜色
    override var preferredStatusBarStyle: UIStatusBarStyle {
        return .default
    }

    /// 子类控制器自定义状态栏颜色
    override var childViewControllerForStatusBarStyle: UIViewController? {
        return topViewController
    }
    
    /// push
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if self.viewControllers.count != 0 {
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: true)
    }
}

public extension UINavigationController {

    /// 先pop，后push
    func popCurrentAndPush(vc: UIViewController, animated: Bool) {
        var vcs = self.viewControllers
        guard !vcs.isEmpty else { return }
        vcs.removeLast()
        vcs.append(vc)
        self.setViewControllers(vcs, animated: animated)
    }
}
